import sys
from PyQt5 import QtCore, QtGui, QtWidgets
import qtawesome

class TestLayout(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.init_ui()
        self.ui_style()
        self.closeBtn()

    def init_ui(self):
        self.setWindowTitle('傻不拉几')
        self.setMinimumSize(680,500)
        self.setMaximumSize(980,600)
        self.main_widget = QtWidgets.QWidget()
        self.main_layout = QtWidgets.QGridLayout()
        self.main_widget.setLayout(self.main_layout)

        self.left_widget = QtWidgets.QWidget()
        self.left_widget.setObjectName('left_widget')
        self.left_layout = QtWidgets.QGridLayout()
        self.left_widget.setLayout(self.left_layout)

        self.right_widget = QtWidgets.QWidget()
        self.right_widget.setObjectName('right_widget')
        self.right_layout = QtWidgets.QGridLayout()
        self.right_widget.setLayout(self.right_layout)

        self.main_layout.addWidget(self.left_widget,0,0,11,2)
        self.main_layout.addWidget(self.right_widget,0,2,11,10)
        self.setCentralWidget(self.main_widget)

        self.left_button1 = QtWidgets.QPushButton("")
        self.left_button2 = QtWidgets.QPushButton("")
        self.left_button3 = QtWidgets.QPushButton("")

        # self.left_label1 = QtWidgets.QLabel("每日推荐")
        # self.left_label1.setObjectName('left_label')
        # # self.left_label1.setBackgroundRole("")
        # self.left_label1.setAutoFillBackground(True)
        # self.left_label2 = QtWidgets.QLabel("我的音乐")
        # self.left_label2.setObjectName('left_label')
        # self.left_label2.setAutoFillBackground(True)
        # self.left_label3 = QtWidgets.QLabel("联系与帮助")
        # self.left_label3.setObjectName('left_label')
        # self.left_label3.setAutoFillBackground(True)
        # self.palette = QtGui.QPalette()
        # self.palette.setColor(QtGui.QPalette.Window, QtCore.Qt.yellow)
        # self.left_label1.setPalette(self.palette)
        # self.left_label2.setPalette(self.palette)
        # self.left_label3.setPalette(self.palette)
        #
        # self.left_btn1 = QtWidgets.QPushButton("a")
        # self.left_btn1.setObjectName('left_button')
        # self.left_btn2 = QtWidgets.QPushButton("b")
        # self.left_btn2.setObjectName('left_button')
        # self.left_btn3 = QtWidgets.QPushButton("c")
        # self.left_btn3.setObjectName('left_button')
        # self.left_btn4 = QtWidgets.QPushButton("d")
        # self.left_btn4.setObjectName('left_button')
        # self.left_btn5 = QtWidgets.QPushButton("e")
        # self.left_btn5.setObjectName('left_button')
        # self.left_btn6 = QtWidgets.QPushButton("f")
        # self.left_btn6.setObjectName('left_button')
        # self.left_btn7 = QtWidgets.QPushButton("g")
        # self.left_btn7.setObjectName('left_button')

        self.left_layout.addWidget(self.left_button1,0,0,1,1)
        self.left_layout.addWidget(self.left_button2,0,1,1,1)
        self.left_layout.addWidget(self.left_button3,0,2,1,1)
        # self.left_layout.addWidget(self.left_label1,1,0,1,3)
        # self.left_layout.addWidget(self.left_btn1,2,0,1,3)
        # self.left_layout.addWidget(self.left_btn2,3,0,1,3)
        # self.left_layout.addWidget(self.left_btn3,4,0,1,3)
        # self.left_layout.addWidget(self.left_label2,5,0,1,3)
        # self.left_layout.addWidget(self.left_btn4,6,0,1,3)
        # self.left_layout.addWidget(self.left_btn5,7,0,1,3)
        # self.left_layout.addWidget(self.left_btn6,8,0,1,3)
        # self.left_layout.addWidget(self.left_label3,9,0,1,3)
        # self.left_layout.addWidget(self.left_btn7,10,0,1,3)

        self.right_search_widget = QtWidgets.QWidget()
        self.right_search_layout = QtWidgets.QGridLayout()
        # self.right_search_widget.setLayout(self.right_search_layout)
        self.right_search_widget.setLayout(self.right_search_layout)
        self.right_search_lb = QtWidgets.QLabel(chr(0xf002)+' '+'搜索 ')
        self.right_search_lb.setFont(qtawesome.font('fa',16))
        # self.right_search_lb = QtWidgets.QLabel()
        self.right_search_input = QtWidgets.QLineEdit()
        self.right_search_input.setPlaceholderText("输入歌手、歌曲或用户，回车进行搜索")
        self.right_search_layout.addWidget(self.right_search_lb,0,0,1,1)
        self.right_search_layout.addWidget(self.right_search_input,0,1,1,8)
        self.right_layout.addWidget(self.right_search_widget,0,0,1,9)

        self.right_recommend_lb = QtWidgets.QLabel('今日推荐')
        self.right_recommend_lb.setObjectName('right_label')
        self.right_recommend_widget = QtWidgets.QWidget()
        self.right_recommend_layout = QtWidgets.QGridLayout()
        self.right_recommend_widget.setLayout(self.right_recommend_layout)

        self.right_recommend_btn1 = QtWidgets.QToolButton()
        self.right_recommend_btn1.setText('歌曲1')
        self.right_recommend_btn1.setIcon(QtGui.QIcon('./r3.jpg'))
        self.right_recommend_btn1.setIconSize(QtCore.QSize(100,100))
        self.right_recommend_btn1.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.right_recommend_btn2 = QtWidgets.QToolButton()
        self.right_recommend_btn2.setText('歌曲2')
        self.right_recommend_btn2.setIcon(QtGui.QIcon('./r3.jpg'))
        self.right_recommend_btn2.setIconSize(QtCore.QSize(100,100))
        self.right_recommend_btn2.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.right_recommend_btn3 = QtWidgets.QToolButton()
        self.right_recommend_btn3.setText('歌曲3')
        self.right_recommend_btn3.setIcon(QtGui.QIcon('./r3.jpg'))
        self.right_recommend_btn3.setIconSize(QtCore.QSize(100,100))
        self.right_recommend_btn3.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.right_recommend_btn4 = QtWidgets.QToolButton()
        self.right_recommend_btn4.setText('歌曲4')
        self.right_recommend_btn4.setIcon(QtGui.QIcon('./r3.jpg'))
        self.right_recommend_btn4.setIconSize(QtCore.QSize(100,100))
        self.right_recommend_btn4.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.right_recommend_btn5 = QtWidgets.QToolButton()
        self.right_recommend_btn5.setText('歌曲5')
        self.right_recommend_btn5.setIcon(QtGui.QIcon('./r3.jpg'))
        self.right_recommend_btn5.setIconSize(QtCore.QSize(100,100))
        self.right_recommend_btn5.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.right_recommend_layout.addWidget(self.right_recommend_btn1,0,0)
        self.right_recommend_layout.addWidget(self.right_recommend_btn2,0,1)
        self.right_recommend_layout.addWidget(self.right_recommend_btn3,0,2)
        self.right_recommend_layout.addWidget(self.right_recommend_btn4,0,3)
        self.right_recommend_layout.addWidget(self.right_recommend_btn5,0,4)

        self.right_layout.addWidget(self.right_recommend_lb,1,0,1,9)
        self.right_layout.addWidget(self.right_recommend_widget,2,0,2,9)

        self.new_song_lb = QtWidgets.QLabel('最新歌曲')
        self.new_song_lb.setObjectName('right_label')
        self.new_song_widget = QtWidgets.QWidget()
        self.new_song_layout = QtWidgets.QGridLayout()
        self.new_song_widget.setLayout(self.new_song_layout)

        self.new_song_btn1 = QtWidgets.QPushButton()
        self.new_song_btn1.setText("新歌")
        self.new_song_btn2 = QtWidgets.QPushButton()
        self.new_song_btn2.setText("新歌")
        self.new_song_btn3 = QtWidgets.QPushButton()
        self.new_song_btn3.setText("新歌")
        self.new_song_btn4 = QtWidgets.QPushButton()
        self.new_song_btn4.setText("新歌")
        self.new_song_btn5 = QtWidgets.QPushButton()
        self.new_song_btn5.setText("新歌")
        self.new_song_btn6 = QtWidgets.QPushButton()
        self.new_song_btn6.setText("新歌")

        self.new_song_layout.addWidget(self.new_song_btn1)
        self.new_song_layout.addWidget(self.new_song_btn2)
        self.new_song_layout.addWidget(self.new_song_btn3)
        self.new_song_layout.addWidget(self.new_song_btn4)
        self.new_song_layout.addWidget(self.new_song_btn5)
        self.new_song_layout.addWidget(self.new_song_btn6)

        self.right_layout.addWidget(self.new_song_lb,4,0,1,5)
        self.right_layout.addWidget(self.new_song_widget,5,0,1,5)


        self.hot_song_lb = QtWidgets.QLabel('热门歌单')
        self.hot_song_lb.setObjectName('right_label')
        self.hot_song_widget = QtWidgets.QWidget()
        self.hot_song_layout = QtWidgets.QGridLayout()
        self.hot_song_widget.setLayout(self.hot_song_layout)

        self.hot_song_btn1 = QtWidgets.QToolButton()
        self.hot_song_btn1.setText("热门")
        self.hot_song_btn1.setIcon(QtGui.QIcon('./r1.jpg'))
        self.hot_song_btn1.setIconSize(QtCore.QSize(100,100))
        self.hot_song_btn1.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.hot_song_btn2 = QtWidgets.QToolButton()
        self.hot_song_btn2.setText("热门")
        self.hot_song_btn2.setIcon(QtGui.QIcon('./r1.jpg'))
        self.hot_song_btn2.setIconSize(QtCore.QSize(100,100))
        self.hot_song_btn2.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.hot_song_btn3 = QtWidgets.QToolButton()
        self.hot_song_btn3.setText("热门")
        self.hot_song_btn3.setIcon(QtGui.QIcon('./r1.jpg'))
        self.hot_song_btn3.setIconSize(QtCore.QSize(100,100))
        self.hot_song_btn3.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.hot_song_btn4 = QtWidgets.QToolButton()
        self.hot_song_btn4.setText("热门")
        self.hot_song_btn4.setIcon(QtGui.QIcon('./r1.jpg'))
        self.hot_song_btn4.setIconSize(QtCore.QSize(100,100))
        self.hot_song_btn4.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.hot_song_layout.addWidget(self.hot_song_btn1,0,0)
        self.hot_song_layout.addWidget(self.hot_song_btn2,0,1)
        self.hot_song_layout.addWidget(self.hot_song_btn3,1,0)
        self.hot_song_layout.addWidget(self.hot_song_btn4,1,1)

        self.right_layout.addWidget(self.hot_song_lb,4,5,1,4)
        self.right_layout.addWidget(self.hot_song_widget,5,5,1,4)


        self.right_process_bar = QtWidgets.QProgressBar()
        self.right_process_bar.setFixedHeight(3)
        self.right_process_bar.setValue(49)
        self.right_process_bar.setTextVisible(False)

        self.right_playconsole_widget = QtWidgets.QWidget()
        self.right_playconsole_layout = QtWidgets.QGridLayout()
        self.right_playconsole_widget.setLayout(self.right_playconsole_layout)

        self.console_btn1 = QtWidgets.QPushButton(qtawesome.icon('fa.backward', color='#F76677'), "")
        self.console_btn2 = QtWidgets.QPushButton(qtawesome.icon('fa.forward', color='#F76677'), "")
        self.console_btn3 = QtWidgets.QPushButton(qtawesome.icon('fa.pause', color='#F76677', font=18), "")
        self.console_btn3.setIconSize(QtCore.QSize(30,30))

        self.right_playconsole_layout.addWidget(self.console_btn1,0,0)
        self.right_playconsole_layout.addWidget(self.console_btn2,0,2)
        self.right_playconsole_layout.addWidget(self.console_btn3,0,1)
        self.right_playconsole_layout.setAlignment(QtCore.Qt.AlignCenter)

        self.right_layout.addWidget(self.right_process_bar,9,0,1,9)
        self.right_layout.addWidget(self.right_playconsole_widget,10,0,1,9)

    def ui_style(self):
        self.left_button1.setFixedSize(15,15)
        self.left_button2.setFixedSize(15,15)
        self.left_button3.setFixedSize(15,15)
        self.left_button1.setStyleSheet('''QPushButton{background:#F76677;border-radius:5px;}QPushButton:hover{background:red;}''')
        self.left_button2.setStyleSheet('''QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}''')
        self.left_button3.setStyleSheet('''QPushButton{background:#F7D674;border-radius:5px;}QPushButton:hover{background:yellow;}''')

        self.left_widget.setStyleSheet('''
            QPushButton{border:none;color:white;}
            QLabel#left_label{
                color:white;
                border:none;
                border-bottom:1px solid white;
                font-size:18px;
                font-weight:700;
                font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;}
            QPushButton#left_button:hover{border-left:4px solid red;font-weight:700;}
            QWidget#left_widget{
                background:black;
                border-top:1px solid white;
                border-bottom:1px solid white;
                border-left:1px solid white;
                border-top-left-radius:10px;
                border-bottom-left-radius:10px;
            }''')
        self.right_search_input.setStyleSheet('''
            QLineEdit{
                border:1px solid gray;
                width:300px;
                border-radius:10px;
                padding:2px 4px;
                } ''')
        self.right_widget.setStyleSheet('''
            QWidget#right_widget{
                color:#232c51;
                background:white;
                border-top:1px solid darkgray;
                border-bottom:1px solid darkgray;
                border-right:1px solid darkgray;
                border-top-right-radius:10px;
                border-bottom-right-radius:10px;
            }
            QLabel#right_label{
                border:none;
                font-size:16px;
                font-weight:700;
                font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
            }''')
        self.right_recommend_widget.setStyleSheet('''
            QToolButton{border:1px solid lightgray;}
            QToolButton:hover{border-bottom:2px solid #F76677}
            ''')
        self.hot_song_widget.setStyleSheet('''
            QToolButton{border:1px solid lightgray;}
            QToolButton:hover{border-bottom:2px solid #F76677}
            ''')
        self.new_song_widget.setStyleSheet('''
            QPushButton{
            border:1px solid lightgray;
            color:gray;
            font-size:12px;
            height:40px;
            padding-left:5px;
            padding-right:10px;
            text-align:left;
            }
            QPushButton:hover{
            color:black;
            border:1px solid #F3F3F5;
            border-radius:10px;
            background:LightGray;
            }''')
        self.right_process_bar.setStyleSheet('''
            QProgressBar::chunk {
            background-color: #F76677;}
            ''')
        self.right_playconsole_widget.setStyleSheet('''
            QPushButton{border:none;}
            ''')
        self.setWindowOpacity(0.9)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
        self.main_layout.setSpacing(0)


    def mousePressEvent(self, event):
        if event.button()==QtCore.Qt.LeftButton:
            self.m_drag = True
            self.m_DragPosition = event.globalPos()-self.pos()
            event.accept()
            self.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))

    def mouseMoveEvent(self, QMouseEvent):
        if QtCore.Qt.LeftButton and self.m_drag:
            self.move(QMouseEvent.globalPos()-self.m_DragPosition)
            QMouseEvent.accept()

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_drag = False
        self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

    def closeBtn(self):
        self.left_button1.clicked.connect(self.close)


def main():
    app = QtWidgets.QApplication(sys.argv)
    gui = TestLayout()
    gui.show()
    sys.exit(app.exec())

if __name__ == '__main__':
    main()